package com.wzl.mixed.controller;

import com.wzl.common.VkPublicResponse;
import com.wzl.common.pojo.VkSmbmsUser;
import com.wzl.mixed.config.ApplicationContextUtil;
import com.wzl.mixed.service.impl.APContextServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 全局上下文对象获取控制器
 *
 * @author wzl
 * @since 1.0, 2023/06/09 11:18
 */
@Controller
@RequestMapping("/context")
@Slf4j
public class APContextController {

    @Resource
    private ApplicationContext applicationContext;

    @RequestMapping("/test")
    @ResponseBody
    public VkPublicResponse task() {

        APContextServiceImpl apContextService = ApplicationContextUtil.getBean(APContextServiceImpl.class);
        String test = apContextService.test();
        log.info("通过implements ApplicationContextAware获取得到的bean对象：{}", test);

        APContextServiceImpl apContextService1  = applicationContext.getBean(APContextServiceImpl.class);
        String test1 = apContextService1.test();
        log.info("通过@Resource ApplicationContext获取得到的bean对象：{}",test1);

        return new VkPublicResponse();
    }

}
